# -*- coding: utf-8 -*-
"""
Created on Mon Apr 02 21:03:44 2018
@author: Fsl
"""
import shutil
import os
import tqdm
#这个库复制文件比较省事
 
def objFileName():
    '''
    生成文件名列表
    :return:
    '''
    local_file_name_list = r'train.txt'
    #指定名单
    obj_name_list = []
    for i in open(local_file_name_list,'r'):
        obj_name_list.append(i.replace('\n',''))
    return obj_name_list
 
def copy_img():
    '''
    复制、重命名、粘贴文件
    :return:
    '''
    local_img_name=r'/media/hjh/workdir/0_Deep_Learning/磁瓦/测试数据集/语义分割（背面）'
    # local_img_name=r'I:\0_Deep_Learning\磁瓦\磁瓦数据集_1_3_正面--sss\1工位\dataset_split\temp_t'
    # local_img_name = os.path.join(local_img_name, encoding='UTF-8')
    #指定要复制的图片路径

    path = r'/media/hjh/workdir/0_Deep_Learning/datasets/ciwa_beimian_VOC2007/JPEGImages'
    # path = os.path.join(path, encoding='UTF-8')
    #指定存放图片的目录
    j = 0
    for i in tqdm.tqdm(objFileName()):
        new_obj_name = i #+'.txt'
        try:
            shutil.copy(local_img_name+'/'+new_obj_name, path+'/'+new_obj_name)     # 剪切：move
            # print('copy ', new_obj_name)
            j += 1
        except:
            print("error") 
    print(j,'个')   
        
 
if __name__ == '__main__':
    copy_img()